package kernel.udp.requests;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Hashtable;


public class HandlerFinder{

	public Hashtable<String, Class> myComponents = new Hashtable<String, Class>();

	
	public String invoke(String aClass, String aMethod, Class[] params, Object[] args) throws Exception {

		
		Class c = myComponents.get(aClass);			
	    Method m = c.getDeclaredMethod(aMethod, params);	    
	    Object i = c.newInstance();
	    Object r = m.invoke(i, args);	
	    
	    return toXML(r);
	    
	}
	
	public String toXML(Object r){
		
		if (r instanceof String) return "String-"+r;
		else if (r instanceof String) return "Integer-"+((Integer)r).toString();
		else if (r instanceof Double) return "Double-"+((Double)r).toString();
		else if (r instanceof Boolean) return "Boolean-"+((Boolean)r).toString();
		else return "Null";
		
	}
	
	public void addHandler(String componentName, Class myClass){
		myComponents.put(componentName, myClass);
	}
	
	
	
}
